home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12713 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  60 lines

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Help!  Can't read input from keyboard!
  5. Date: 2 Apr 1996 06:58:50 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4jr8aa$hf8@solutions.solon.com>
  8. References: <4jq0ts$5mh@taniemarie.solon.com> <1APR199622404442@erich.triumf.ca>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <1APR199622404442@erich.triumf.ca>,
  12. P.Bennett <bennett@erich.triumf.ca> wrote:
  13. >In article <4jq0ts$5mh@taniemarie.solon.com>, seebs@taniemarie.solon.com (Peter Seebach) writes...
  14. >>gcc -g -O -Wa,ll -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes
  15.  
  16. >It would help if you posted the _real_ code so we would know there weren't any
  17. >typos...
  18.  
  19. I really did, and if you compile it with that setup, you will notice that you
  20. get a *warning* from your assembler stating that "ll" is not a valid
  21. option.  (With my assembler, anyway.)  With an actual -Wall, of course,
  22. it correctly warns for the mistake.
  23.  
  24. >>    #include <stdio.h>
  25.  
  26. >>    int main(void) {
  27. >>        int i = 0;
  28.  
  29. >>        (void) sscanf, "3", "%d", i;
  30.  
  31. >This won't compile as is - it needs some parentheses, like:
  32. >        (void) sscanf("3", "%d", i);
  33. >If this is what your real code says, then you need to change it to:
  34. >        (void) sscanf("3", "%d", &i);
  35. >Since sscanf() must change i, you have to pass i's _address_, using &i.
  36.  
  37. But the code *will* compile as is, and is legal; it evaluates to 0, after
  38. evaluating "scanf", "%d", and "i" for their side effects.
  39.  
  40. >>        (void) printf, "%d", i;
  41. >this must have some parentheses as well:
  42. >        (void) printf("%d", i);
  43.  
  44. Ditto here.  Perfectly legal, just not useful.
  45.  
  46. >The arguments for the sscanf() and printf() families are similar, but not
  47. >identical - scanf() needs the _address_ of its arguments, and printf() does
  48. >not.  There are also some differences in the format specifiers.
  49.  
  50. I knew that.  :)
  51.  
  52. Happy April Fools Day!
  53.  
  54. -s
  55. -- 
  56. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  57. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  58. FUCK the communications decency act.  Goddamned government.  [literally.]
  59. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  60.